package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsInvoicePinDto;
import com.sale.goods.domain.vo.GoodsInvoicePinVo;
import com.sale.goods.service.IGoodsInvoicePinService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 销项税发票
 * @Date 23-07-19
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/invoicePin")
public class GoodSInvoicePinController extends BaseController {

    private final IGoodsInvoicePinService goodSInvoicePinService;


    /**
     * 获取销项税发票
     */
    //@SaCheckPermission("finance:destructionTax:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsInvoicePinDto> list(GoodsInvoicePinVo goodSInvoicePinVo, PageQuery pageQuery)
    {
        return goodSInvoicePinService.selectInvoicePinList(goodSInvoicePinVo,pageQuery);
    }

    /**
     * 新增销项税发票
     */
    //@SaCheckPermission("finance:destructionTax:add")
    @Log(title = "销项税发票", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsInvoicePinVo goodSInvoicePinVo) throws Exception {
        return toAjax(goodSInvoicePinService.insertInvoicePin(goodSInvoicePinVo));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{invoicePinId}")
    //@SaCheckPermission("finance:destructionTax:query")
    public R getInfo(@PathVariable long invoicePinId)
    {
        return R.ok(goodSInvoicePinService.selectInvoicePinById(invoicePinId));
    }

    /**
     * 删除销项税发票
     */
    //@SaCheckPermission("finance:destructionTax:remove")
    @Log(title = "销项税发票", businessType = BusinessType.DELETE)
    @DeleteMapping("/{invoicePinId}")
    public R<Void> remove(@PathVariable("invoicePinId") Long invoicePinId) {
        return toAjax(goodSInvoicePinService.deleteInvoicePinById(invoicePinId));
    }

    /**
     * 修改销项税发票
     */
    //@SaCheckPermission("finance:destructionTax:edit")
    @Log(title = "销项税发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsInvoicePinVo goodSInvoicePinVo) {
        return toAjax(goodSInvoicePinService.updateInvoicePinEdit(goodSInvoicePinVo));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:destructionTax:subExamine")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{invoicePinId}")
    public R<Void> submitReview(@PathVariable("invoicePinId") Long invoicePinId) {
        return toAjax(goodSInvoicePinService.submitReview(invoicePinId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:destructionTax:revoke")
    @Log(title = "撤销审核", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{invoicePinId}")
    public R<Void> deleteReview(@PathVariable("invoicePinId") Long invoicePinId) {
        return toAjax(goodSInvoicePinService.deleteReview(invoicePinId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("goods:invoicePin:review")
    @Log(title = "审核单据", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsInvoicePinVo goodSInvoicePinVo) throws Exception {
        return toAjax(goodSInvoicePinService.goodSExamineReview(goodSInvoicePinVo));
    }

    /**
     * 认证
     */
    //@SaCheckPermission("goods:invoicePin:goodsThe")
    @Log(title = "提交审核", businessType = BusinessType.UPDATE)
    @GetMapping("/goodsThe/{invoicePinId}")
    public R<Void> goodsThe(@PathVariable("invoicePinId") Long invoicePinId) {
        return toAjax(goodSInvoicePinService.goodsThe(invoicePinId));
    }


}
